package com.bang.itstack.day05;

/**
 * @ClassName: Singleton01
 * @Desc: 内部枚举
 * @author: <Bang>
 * @Date: 2021/10/21 19:19
 * @Version: 1.0
 * @Modified By:
 */
public class Singleton06 {

    private Singleton06() {
    }

    //定义一个静态枚举类
    static enum SingletonEnum{
        //创建一个枚举对象，该对象天生为单例
        INSTANCE;
        private Singleton06 instance;
        //私有化枚举的构造函数
        private SingletonEnum(){
            instance=new Singleton06();
        }
        public Singleton06 getInstance(){
            return instance;
        }
    }

    public static Singleton06 getInstance() {
        return SingletonEnum.INSTANCE.getInstance();
    }

    public static void main(String[] args) {
        System.out.println(Singleton06.getInstance());
        System.out.println(Singleton06.getInstance());
        System.out.println(Singleton06.getInstance());
    }

}
